<?php
/**
 * Created by JetBrains PhpStorm.
 * User: cgp
 * Date: 13-4-6
 * Time: 上午12:18
 * To change this template use File | Settings | File Templates.
 */

class SceneryProduct extends Product {

    const PRODUCT_WITH_TICKETS = true;
    const OPEN_DEBUG = true;
    const COUNT_TOTAL = 1;
    const NO_COUNT_TOTAL = 0;
    /**
     * 添加景区门票
     * @param $data
     * @param $dprice  接口获取到的结算价和配置给他的价格的差价, 单位为分
     * @return array
     * update:2013年9月29日10:22:47
     *        KH sayed 取消向price_set表写数据
     */
    public function AddTickets($data,$dprice=0, $debug=false) {
        //echo $dprice;
        //exit;
        //TODO-done:验证景区是否已经存在，不存在的禁止添加
        if(! parent::_chkProExist($data['landid'], 'id','uu_land')) {
            //echo '2';
            return array('errcode'=>1004,'msg'=>'景区不存在，添加失败');
        }

        $str = "INSERT INTO `uu_jq_ticket` SET ";
        $str .= $this->getValues($data);
        if($debug) {
            echo 'AddTickets = ', $str ,"<br/>\n";
        }
        if($GLOBALS['le']->query($str)) {
            $lastid = _mysql_insert_id();
            $pid = parent::_getPid($lastid, $debug);

            $arrReturn = array(
                'lastid'=>$lastid,
                'pid'=>$pid,
                'landid'=>$data['landid']
            );
            $arrReturn['errcode']=1000;

            return $arrReturn;
        }
        return $this->ErrArr;
    }

    private function _count_by_state($apply_did) {
        $t = array();
        $str = "SELECT count(*) as t,status FROM uu_land ".
            "WHERE `apply_did`={$apply_did} GROUP BY status";
        try{
            $GLOBALS['le']->query($str);
            while($r = $GLOBALS['le']->fetch_assoc()) {
                $t[$r['status']] = $r['t'];
            }
            return $t;

        } catch(Exception $e) {
            return $e->getMessage();
        }
    }
    private function _count_by_ptype($apply_did) {
        $t = array();
        $str = "SELECT count(*) as t,p_type FROM uu_land ".
            "WHERE `apply_did`={$apply_did} GROUP BY p_type";
        try{
            $GLOBALS['le']->query($str);
            while($r = $GLOBALS['le']->fetch_assoc()) {
                $t[$r['p_type']] = $r['t'];
            }
            return $t;

        } catch(Exception $e) {
            return $e->getMessage();
        }
    }
     public function CountProductByState($apply_did, $conut_type='state'){
         if(!$apply_did){
             return;
         }
         switch($conut_type) {
             case 'state':
                 return $this->_count_by_state($apply_did);
                 break;
             case 'ptype':
                 return $this->_count_by_ptype($apply_did);
                 break;
             default:break;
         }
     }
    /**
     * 获取景区列表
     * @param $params array
     *      title 景区名称
     *      salerid 商户编号
     *      topic 景区主题
     *      btime 添加时间开始
     *      etime 添加时间结束
     *      orderby 排序字段默认（id)
     *      order 升序（1默认）或降序（0）
     *      limit 数据起始记录
     *      offset 获取条数
     * @return array|mixed
     */
    public function GetSceneryLists($params, $count=0, $ticketsFlag=false,
                                    $debug=false) {
        $where = '';
        if(strpos($params['status'],',')!==false) {
            $where .= " AND l.status IN({$params['status']})";
        }
        elseif(is_numeric($params['status']) && $params['status']!=4) {
            $where .= " AND l.status={$params['status']}";
        }
        else {
            $where .= " AND l.status<> 3 ";
        }
        if(!empty($params['title'])) {
            $where .= " AND l.`title` LIKE '%{$params['title']}%'";
        }
        if(!empty($params['salerid'])) {
            $where .= " AND l.`salerid` = {$params['salerid']}";
        }
        if(!empty($params['topic'])) {
            $where .= " AND l.`topic` LIKE '%{$params['topic']}%'";
        }
        if(isset($params['ptype'])) {
            $where .= " AND l.p_type ='{$params['ptype']}'";
        }
        if(!empty($params['bt']) && !empty($params['et'])) {
            $where .= " AND l.`addtime` BETWEEN '{$params['bt']}' AND '{$params['et']}'";
        }
        if(isset($params['applyer'])) {
            $where .= " AND l.apply_did={$params['applyer']}";
        }
        if($count) {
            $str = "SELECT COUNT(*) as c FROM uu_land l LEFT JOIN uu_biz_info b"
                ." ON (l.salerid=b.bid)  WHERE 1=1". $where;
            //echo $str;
            $GLOBALS['le']->query($str);
            $GLOBALS['le']->fetch_assoc();
            return $GLOBALS['le']->f('c');
        }
        $str = <<<SQL
            SELECT l.id,l.title,l.area,l.address,l.jtype,l.addtime,
            l.taobao_support,l.passtime,l.salerid,l.px,l.status,l.topic,
            l.keywords,l.description,l.apply_did,l.p_type,l.attribute,
            l.imgpath, t.id as ticket_id,t.landid,t.title as ticket_title,
            t.tprice,t.px,t.pay,t.storage,t.s_limit_up,t.s_limit_low,
            t.delaydays,t.ddays,t.getaddr,t.buy_limit_up,t.buy_limit_low,
            t.apply_did,t.pid, p.apply_did as appid,p.apply_limit,p.p_status,
            p.verify_op,p.verify_time
            FROM uu_land l LEFT JOIN uu_jq_ticket t ON t.landid=l.id
            LEFT JOIN uu_products p ON t.pid=p.id
            WHERE 1=1 {$where}
            AND p.p_status<>6
SQL;

        //$str .= $where;

        $orderby = !empty($params['orderby']) ? 'l.'.$params['orderby'] : 'l.id';
        $order = $params['sort'] ==1 ? 'ASC' : 'DESC';
        $str .= " ORDER BY {$orderby} {$order},l.addtime DESC";
        $str .= " LIMIT {$params['limit']},{$params['offset']}";
        if($debug) {
            echo $str;
        }
        $lists = array();
        $GLOBALS['le']->query($str);
        while($rows = $GLOBALS['le']->fetch_assoc()) {
            $tickets[$rows['id']][] = array(
                'id'     =>$rows['ticket_id'],
                'title'  =>$rows['ticket_title'],
                'tprice' =>$rows['tprice'],
                'storage' =>$rows['storage'],
                's_limit_up' =>$rows['s_limit_up'],
                's_limit_low' =>$rows['s_limit_low'],
                'apply_did' =>$rows['apply_did'],
                'pid'       =>$rows['pid'],
                'apply_limit' =>$rows['apply_limit'],
                'p_status' =>$rows['p_status'],
                'verify_op' =>$rows['verify_op'],
                'passtime' =>$rows['passtime'],
                'verify_time' =>$rows['verify_time'],
            );
            $lists[$rows['id']] = array(
                'id'     => $rows['id'],
                'title'  => $rows['title'],
                'area'  => $rows['area'],
                'jtype'  => $rows['jtype'],
                'addtime'  => $rows['addtime'],
                'taobao_support'  => $rows['taobao_support'],
                'salerid'  => $rows['salerid'],
                'px'  => $rows['px'],
                'status'  => $rows['status'],
                'topic'  => $rows['topic'],
                'keywords'  => $rows['keywords'],
                'description'  => $rows['description'],
                'p_type'  => $rows['p_type'],
                'apply_did'  => $rows['apply_did'],
                'imgpath'  => $rows['imgpath'],
                'tickets'=>$tickets[$rows['id']]
            );
        }
        //print_r($lists);
        return $lists;
    }

    /**
     * 获取分销可分销的产品
     * @param $did 产品ID
     * @return array
     */
    public function GetSalesProducts($did) {
        $str="select p.*id from uu_products p left join uu_priceset b "
            . " on p.id=b.tid where b.pid={$did} and b.num>0 and "
            . " p.p_status in (0,3,4,5) and p.apply_limit=1 ";
        $pid_arr = array();
        $GLOBALS['le']->query($str);
        while($rows = $GLOBALS['le']->fetch_assoc()) {
            $pid_arr[] = $rows['id'];
        }
        $pid_str = implode(',', $pid_arr);
        $str2 = "SELECT l.title as ptitle, t.title as ttitle,t.pid,t.delaydays "
            . " FROM uu_land l,uu_jq_ticket t WHERE t.pid IN ({$pid_str})";
        echo $str2;
        $output_arr = array();
        $GLOBALS['le']->query($str2);
        while($rows = $GLOBALS['le']->fetch_assoc()) {
            //echo $rows['ptitle'];
            $output_arr[] = $rows;
        }
        print_r($output_arr);
        return $output_arr;
    }

    public function GetProductsLimit($did, $ctype=null, $bt=null, $et=null, $debug=false){
        $bt = !$bt ? date('Y-m-d',strtotime('-7 days')) : $bt;
        $et = !$et ? date('Y-m-d') : $et;
        $str1 = "select distinct (v.pid) ,b.tid,v.ctype,".
            "date_format(v.created_at,'%Y%m%d') as ct from uu_priceset b,";
        $str1 .= "uu_prod_verify v where b.pid=$did and v.pid=b.tid";
        $str1 .= !$ctype ? " and v.ctype>0 " : " and v.ctype=$ctype";
        $str1 .= " and v.created_at between('{$bt} 00:00:00') and ('{$et} 23:59:59')";
        //echo $str1;
        if($debug) {
            echo $str1;
        }
        $GLOBALS['le']->query($str1);
        $prod_list = array();
        $prod_list2 = array();
        $pid_list = array();
        while($rows = $GLOBALS['le']->fetch_assoc()) {
            //$ct = strtotime($rows['ct']);
            $prod_list[$rows['ct']][$rows['ctype']] += 1;
            $pid_list[] = $rows['tid'];
        }
        if(!$ctype) {
            //print_r($prod_list);
            return $prod_list;
        }
        if(!count($pid_list)) {
            return array();
        }
        $pid = implode(',', $pid_list);
        $str2 = "select t.title as t_title,l.p_type,l.title as p_title,t.landid"
            ." from uu_jq_ticket t,uu_land l ";
        $str2 .= " where t.pid in($pid) AND l.id = t.landid";
        //echo $str2;
        $GLOBALS['le']->query($str2);
        while($rows=$GLOBALS['le']->fetch_assoc($str2)) {
            $prod_list2[] = array(
                'i' => $rows['landid'],
                't' => $rows['t_title'],
                'p' => $rows['p_title'],
                'e' => $rows['p_type']
            );
        }
        return $prod_list2;
    }
    /**
     * 获取所有景区门票列表
     * @param $params
     * @param $count
     * @param $debug 是否打开调试
     * @return array
     */
    public function GetAllTicketList($params, $count=0,$debug=false) {
		$where = " WHERE t.landid=l.id AND t.pid=p.id";
        if(!empty($params['stitle'])) {
            $stitle = trim($params['stitle']);
            $where .= is_numeric($stitle)
                ? " AND l.id={$stitle}"
                : " AND l.title LIKE '%{$stitle}%'";
        }
        if(!empty($params['title'])) {
            $title = trim($params['title']);
            $where .= is_numeric($title)
                ? " AND t.id={$title}"
                :" AND t.title LIKE '%{$title}%'";
        }

        if(is_array($params['landid'])) {
            $where .= " AND t.landid IN (". implode(',',$params['landid']).")";
        }
        elseif(is_numeric($params['landid'])){
            $where .= " AND t.landid={$params['landid']}";
        }

        if(abs($params['applyer'])>0) {
            $where .= " AND p.apply_did={$params['applyer']}";
        }
        if(is_numeric($params['apply_limit'])) {
            $where .= " AND p.apply_limit={$params['apply_limit']}";
        }
        if(is_array($params['status'])) {
            $where .= " AND p.p_status IN(" . implode(',',$params['status']).")";
        }
        elseif($params['status']==-1) {
            $where .= " AND p.p_status<>6";
        }
        elseif($params['status']==0){
            $where .= " AND p.p_status<6 AND p.p_status<>1";
        }
        else {
            $where .= " AND p.p_status='{$params['status']}'";
        }
        if(isset($params['p_type'])) {
            $where .= " AND l.p_type='{$params['p_type']}'";
        }
        if(isset($params['apply_limit'])) {
            $where .= " AND p.apply_limit='{$params['apply_limit']}'";
        }
        if($count) {
            $str = "SELECT COUNT(*) AS c FROM uu_jq_ticket t,uu_products p ,"
                 . "uu_land l " . $where;
            $GLOBALS['le']->query($str);
            $GLOBALS['le']->fetch_assoc();
            return $GLOBALS['le']->f('c');
        }
        else{
            $str = "SELECT t.id,t.landid,t.title,t.tprice,t.px,t.pay,t.storage,"
                . "t.s_limit_up,t.s_limit_low,t.delaydays,t.ddays,t.getaddr,"
                . "t.buy_limit_up,t.buy_limit_low,t.apply_did,t.pid,"
                . "l.title as stitle,l.status as land_status,l.salerid,"
                . "l.p_type,l.runtime,l.attribute,p.apply_did as appid,p.apply_limit,"
                . "p.p_status,p.verify_op,p.verify_time"
                . " FROM uu_jq_ticket t ,uu_products p ,uu_land l " . $where;
        }
        if(isset($params['orderby'])) {
            if(is_array($params['orderby'])) {
                $tod = "";
                foreach($params['orderby'] as $ord) {
                    $tod .= "{$ord['tbl']}.`{$ord['field']}` {$ord['ud']},";
                }
                $str .= ' ORDER BY ' . rtrim($tod,',');
            }
        }

        $str .= " LIMIT {$params['limit']},{$params['offset']}";
        if($debug) {
            print_r($params);
            echo $str;
        }
        $GLOBALS['le']->query($str);
        $lists = array();
        while($rows = $GLOBALS['le']->fetch_assoc()){
            $lists[] = $rows;
        }
        return $lists;
    }

    /**
     * 获取所有景区门票格式化后的数据列表
     * @param $params
     * @param $count
     * @param $debug 是否打开调试
     * @return array
     */
    public function GetAllTicketListFormat($params, $count=0,$debug=false) {
        $result = $this->GetAllTicketList($params, $count,$debug);
        if($count) {
            return $result;
        }
        $lists = array();
        $tickets = array();
        foreach($result as $rows){
            $tickets[$rows['landid']][] = array(
                'id'            => $rows['id'],
                'title'         => $rows['title'],
                'tprice'        => $rows['tprice'],
                'px'            => $rows['px'],
                'status'        => $rows['status'],
                'p_status'      => $rows['p_status'],
                'pay'           => $rows['pay'],
                'ddays'         => $rows['ddays'],
                'getaddr'       => $rows['getaddr'],
                'delaydays'     => $rows['delaydays'],
                'storage'       => $rows['storage'],
                's_limit_up'    => $rows['s_limit_up'],
                's_limit_low'   => $rows['s_limit_low'],
                'buy_limit_up'  => $rows['buy_limit_up'],
                'buy_limit_low' => $rows['buy_limit_low'],
                'open_time'     => $rows['open_time'],
                'end_time'      => $rows['end_time'],
                'apply_did'     => $rows['apply_did'],
                'verify_time'   => $rows['verify_time'],
                'pid'           => $rows['pid'],
                'verify_op'     => $rows['verify_op'],
                'v_state'=>$rows['apply_limit'],//审核状态
            );
            $lists[$rows['landid']] = array(
                'id'        => $rows['landid'],
                'stitle'    => $rows['stitle'],
                'salerid'   => $rows['salerid'],
                'p_type'    => $rows['p_type'],
                'apply_did' => $rows['apply_did'],
                'addtime'   => $rows['addtime'],
                'lstatus'   => $rows['land_status'],
                'tickets'   => $tickets[$rows['landid']]
            );
        }
        return $lists;
    }

    /**
     * @param $landid
     * @param $did
     * @param int $status
     * @param int $fpriceFlag 是否获取配置给分销商的供应价格
     * @return array
     */
    public function GetTicketByLimit($landid, $did, $status=0, $fpriceFlag=1,
                                     $limit=true)
    {
        $params = array(
            'landid' =>$landid,
            'status'=> $status,
            'apply_limit' => 1,
            'limit' =>0,
            'offset'=>10
        );
        $output = array();
        $lists = $this->GetAllTicketList($params);
//        print_r($lists);
        $soap = SoapInit::GetSoapInside();
        //$strP = "SELECT price FROM uu_priceset WHERE tid= :tid AND pid={$did} LIMIT 1";
        foreach($lists as $list) {
            $fprice = $soap->get_Dynamic_Price_Merge($list['pid'],date("Y-m-d"),2, '', '', 0);//供应价
            $uprice = $soap->get_Dynamic_Price_Merge($list['pid'],date("Y-m-d"),2, '', '', 1);//零售价
            $fprice = $fprice>=0 ? $fprice/100 :'未配';
            $uprice = $uprice>=0 ? $uprice/100 :'未配';
           if($fpriceFlag) {
                $sql = "SELECT s.tid, s.dprice FROM uu_priceset s LEFT JOIN uu_products p ON p.id=s.tid ";
                $sql .= "WHERE s.tid={$list['pid']} AND s.pid={$did} AND (p.p_status=0 OR p.p_status=3) LIMIT 1";
                $GLOBALS['le']->query($sql);
                $GLOBALS['le']->fetch_assoc();
                if(!$GLOBALS['le']->f('tid')) {
                    continue;
                }
                $fprice += $GLOBALS['le']->f('dprice')/100;
           }
            $output[] = array(
                'ticketTitle'=>$list['title'],
                'marketPrice'=>$list['tprice'],
                'salePrice'=>$uprice,
                'setlPrice'=>$fprice,
                'validDays'=> !$list['delaydays']? '当天有效' : $list['delaydays'].'天',
                'num'=>!$list['buy_limit_low']? '不限' :$list['buy_limit_low'].'张起订' ,
                'preOrderDays'=>$list['ddays']==0 ? '可当天预定' : $list['ddays'],
                'prodid'=>$list['pid'],
                'landid'=>$list['landid'],
                'status'=>$list['p_status']
            );
        }
        return $output;
    }
    /**
     * 根据门票ID获取门票数据
     * @param $tid 门票ID
     * @return mixed
     */
    public function GetTicketById($tid, $apply_did='', $bypid=false) {
        $str = " SELECT t.id,t.landid,t.title,t.tprice,t.px,t.pay,t.storage,t.s_limit_up,t.s_limit_low,";
        $str .= "t.buy_limit_up,t.buy_limit_low,t.apply_did,p.p_status,p.apply_limit,p.apply_did as distid ";
        $str .= " FROM uu_jq_ticket t,uu_products p WHERE";
        if($bypid) {
            $str .= " t.pid={$tid} ";
        } else {
            $str .= " t.id={$tid} ";
        }
        $str .= " AND t.pid=p.id";
        $str .= !empty($apply_id)? " AND t.apply_did={$apply_did}" : '';
        $str .= " LIMIT 1";
        //echo $str;
        $GLOBALS['le']->query($str);
        return $GLOBALS['le']->fetch_assoc();
    }

    public function GetProductByTid($tid) {
        $str = "SELECT t.* FROM uu_jq_ticket t WHERE t.id=$tid LIMIT 1";
        $GLOBALS['le']->query($str);
        $ticket = array();
        $scenery = array();
        $ticket = $GLOBALS['le']->fetch_assoc();
        $landid = $ticket['landid'];
        $str2 = "SELECT l.* FROM uu_land l WHERE l.id=$landid LIMIT 1";
        $GLOBALS['le']->query($str2);
        $scenery = $GLOBALS['le']->fetch_assoc();
        return array($ticket,$scenery);
    }

//    public function GetProducts
    /**
     * 获取景区列表
     * @param array $params
     * @param int $count
     * @return array
     */
    public function GetSceneryList($params=array('limit'=>0,'offset'=>10), $count=0){
        $where = '';
        if(!empty($params['title'])) {
            $where .= " AND l.title LIKE '%{$params['title']}%'";
        }
        if(!empty($params['apply_did'])) {
            $where .= " AND l.apply_did={$params['apply_did']}";
        }
        if(is_numeric($params['status']) && $params['status']!=4) {
            $where .= " AND l.status='{$params['status']}'";
        }
        else {
            $where .= " AND l.status<> '3' ";
        }
        if($count) {
            $str = "SELECT COUNT(*) AS c FROM uu_land l,uu_biz_info b WHERE l.salerid=b.bid" . $where;
            $GLOBALS['le']->query($str);
            $GLOBALS['le']->fetch_assoc();
            return $GLOBALS['le']->f('c');
        }
        $str = "SELECT l.id, l.title, l.tel, l.fax, l.area, l.address, l.jtzn, l.jdjj, l.bhjq, l.yllx";
        $str .= ", l.imgpath, l.status, l.px, l.addtime, l.passtime, l.salerid,l.p_type";
        $str .= ",b.lcode FROM uu_land l,uu_biz_info b WHERE l.salerid=b.bid " . $where;

        $str .= " ORDER BY l.status ASC ,l.id DESC";
        $str .= " LIMIT {$params['limit']},{$params['offset']}";
        //echo $str;
        $results = array();
        $GLOBALS['le']->query($str);
        while($rows = $GLOBALS['le']->fetch_assoc()) {
            $results[] = $rows;
        }
        return $results;

    }

    /**
     * 景区状态设置（如果状态不为1，需要更新门票产品的状态为1：禁止销售）
     * @param $id 景区id，数组或数字
     * @param $state 状态
     * @param $oper_name  操作人
     * @return int
     */
    public function SetSceneryState($id,$state,$oper_name=null) {
        $logword = date('Y-m-d H:i:s');
        $stateTxt = array('未审核','在售','下架','删除');
        if(is_array($id)) {
            $lid = implode(',',$id);
        }
        else {
            $lid = rtrim($id,',');
        }
        $str = "UPDATE uu_land SET status='{$state}',`passtime`=now() WHERE id IN ({$lid})";
        //echo $str;
        if($GLOBALS['le']->query($str)) {
            $logword .= "|ID为[{$lid}]的产品被设置为{$stateTxt[$state]}|操作人:{$oper_name}";
            $pidList = array();
            if($state!=1) {
                //若将景区下架，门票下架
                //若将景区删除，则门票也设置为删除状态
                if($state== 3) {
                    $ticketState = 6;
                    $pstate = '';
                }
                else {
                    $ticketState = 1;
                    $pstate = ' AND p_status<6';
                }
                $strGetTickets = "SELECT id,pid FROM uu_jq_ticket WHERE landid IN($lid)";
                //echo $strGetTickets;
                $GLOBALS['le']->query($strGetTickets);
                while($rows = $GLOBALS['le']->fetch_assoc()){
                    $pidList[] = $rows['pid'];
                }
                if(count($pidList)>0) {
                    $pids = implode(',',$pidList);
                    $strUpdate = "UPDATE uu_products SET p_status={$ticketState} WHERE id IN($pids){$pstate}";
                    $GLOBALS['le']->query($strUpdate);
                }
            }
            Log::writeLog($logword, Log::SYSOPT_LOG_PATH);
            return 1000;
        }
        return 1001;
    }

    /**
     * 设置产品“淘宝绑定”属性
     * @param $landid 景区表的ID
     * @param $flag 0不支持1支持
     * @param $oper_name 操作人姓名
     */
    public function setTaoSupport($landid, $flag,$oper_name) {

        $str = "UPDATE uu_land SET taobao_support={$flag} WHERE id={$landid} LIMIT 1";
        if($GLOBALS['le']->query($str)) {
            $flagTxt = $flag==1?'允许':'禁止';
            $logword = date('Y-m-d H:i:s');
            $logword .= "|ID为[{$landid}]的产品“淘宝绑定”属性被设置为{$flagTxt}|操作人:{$oper_name}";
            Log::writeLog($logword, Log::SYSOPT_LOG_PATH);
            return 1;
        }
        else {
            return 0;
        }
    }

    /**
     * 删除景区，同时也好删除终端数据
     * @param $id
     * @return int
     */
    public function RemoveScenery($id) {
        if(is_array($id)) {
            $lid = implode(',',$id);
        }
        else {
            $lid = abs($id);
        }
        $salers = array();
        $strGetSalerid = "SELECT id,salerid FROM uu_land WHERE id IN($lid)";
        //echo $strGetSalerid;
        $GLOBALS['le']->query($strGetSalerid);
        while($rows = $GLOBALS['le']->fetch_assoc()) {
            $salers[] = $rows['salerid'];
            $ids[] = $rows['id'];
        }

        $str = "DELETE FROM uu_land WHERE id IN(".implode(',',$ids).")";
        //echo $str;
        if($GLOBALS['le']->query($str)) {
            $salersid = implode(',',$salers);
            parent::_removeRemoteProd($salersid);
            return 1000;
        }
        return 1001;
    }

    /**
     * 获取关联产品
     * @param $lnkid 景区表ID
     * @param bool $format
     * @return array|string
     */
    public static function GetLnkProds($lnkid, $format = false) {
        if(empty($lnkid)) {
            return '牵涉的产品ID不能为空！';
        }
        $str = "SELECT title,id FROM uu_land WHERE id IN ($lnkid)";
        $lnkPors = array();
        $GLOBALS['le']->query($str);
        while($rows = $GLOBALS['le']->fetch_assoc()) {
            $lnkPors[$rows['id']] = $rows['title'];
        }
        if($format) {
            return implode(',', $lnkPors);
        }
        return $lnkPors;
    }

    /**
     * 设置总库存量
     * @param $le
     * @param $pid
     * @param $storage
     * @return mixed
     */
    static function SetProductTotalStorage($le, $pid, $storage,$storage_open) {
        $str = "UPDATE uu_jq_ticket SET storage={$storage},"
                ."storage_open='$storage_open' WHERE pid=$pid LIMIT 1";
        return $le->query($str);
    }
}